package net.osin.playscalajs.MountPoint

import com.thoughtworks.binding.Binding
import com.thoughtworks.binding.Binding.{MultiMountPoint, Vars}
import org.lrng.binding.html
import org.scalajs.dom.html.Div
import org.scalajs.dom.raw.Event

object ViewMMP {
  private val nums=Vars(1,2,3,4,5)

  val arrayChanged=new MultiMountPoint[Int](nums){

    override protected def set(children: Iterable[Int]): Unit = {
      println("set")
    }

    override protected def splice(from: Int, that: Iterable[Int], replaced: Int): Unit = {
      println("splice","from",from,"that",that,"replace",replaced)
    }
  }

  @html def render:Binding[Div] =
  {
//    arrayChanged.bind
    <div>
      <h2>监听数组的变化</h2>
      {
      for(num<-nums) yield <li>{num.toString}</li>
      }
      {
      <button onclick={ event: Event => nums.value += (10,11,12) }>-</button>
      }
    </div>
  }
}
